#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct yl{
    ll fz;
    ll fm;
};
#define piy pair<yl,yl>
#define pil pair<ll,ll>
#define piyl pair<yl,ll>
#define mp make_pair
#define fi first
#define se second
yl my(ll fzx,ll fmx){// fzx/fmx
    yl ret;
    ret.fm=fmx;
    ret.fz=fzx;
    return ret;
}
yl operator + (yl xx,yl yy){
    yl ans;
    ans.fm=(xx.fm*yy.fm);
    ans.fz=(xx.fm*yy.fz+xx.fz*yy.fm);
    ll gc=__gcd(ans.fm,ans.fz);
    ans.fm/=gc;
    ans.fz/=gc;
    return ans;
}
yl operator - (yl xx,yl yy){
    yl ans;
    ans.fm=(xx.fm*yy.fm);
    ans.fz=(xx.fz*yy.fm-xx.fm*yy.fz);
    ll gc=__gcd(ans.fm,ans.fz);
    ans.fm/=gc;
    ans.fz/=gc;
    return ans;
}
bool operator < (yl xx,yl yy){return xx.fz*yy.fm<xx.fm*yy.fz;}
bool operator > (yl xx,yl yy){return xx.fz*yy.fm>xx.fm*yy.fz;}
bool operator <= (yl xx,yl yy){return xx.fz*yy.fm<=xx.fm*yy.fz;}
bool operator >= (yl xx,yl yy){return xx.fz*yy.fm>=xx.fm*yy.fz;}
bool operator == (yl xx,yl yy){return xx.fz*yy.fm==xx.fm*yy.fz;}
/*ll x[500038];
ll b[500038];
void xg(ll pcur,ll le,ll ri,ll tl,ll tr,ll k){
    if(le<=tl&&tr<=ri){
        b[pcur]+=k;
        x[pcur]+=k*(tr-tl+1);
        return;
    }
    ll mid=(tl+tr)>>1;
    if(b[pcur]!=0){
        x[pcur*2]+=b[pcur]*(mid-tl+1);
        x[pcur*2+1]+=b[pcur]*(tr-mid);
        b[pcur*2]+=b[pcur];
        b[pcur*2+1]+=b[pcur];
        b[pcur]=0;
    }
    if(le<=mid){xg(pcur*2,le,ri,tl,mid,k);}
    if(ri>mid){xg(pcur*2+1,le,ri,mid+1,tr,k);}
    x[pcur]=x[pcur*2]+x[pcur*2+1];
    return;
}
ll cx(ll pcur,ll le,ll ri,ll tl,ll tr){
    ll mid=(tl+tr)>>1;
    if(b[pcur]!=0){
        x[pcur*2]+=b[pcur]*(mid-tl+1);
        x[pcur*2+1]+=b[pcur]*(tr-mid);
        b[pcur*2]+=b[pcur];
        b[pcur*2+1]+=b[pcur];
        b[pcur]=0;
    }
    if(le<=tl&&tr<=ri){
        return x[pcur];
    }
    ll su=0;
    if(le<=mid){su+=cx(pcur*2,le,ri,tl,mid);}
    if(ri>mid){su+=cx(pcur*2+1,le,ri,mid+1,tr);}
    return su;
}*/
ll n,m;
vector<piy> car;
vector<yl> csy;
vector<pil> card;//the detective that a car needs
vector<piyl> seq;//mod 4 is (1:CarStart 2:CarEnd 3:detective)
//unordered_map<ll,ll> nc;//0:no detectives ; other:node of first detective
ll nc[100038];
vector<ll> ncn;
bool ncnt[100038];
vector<pil> qj;
yl eps;
ll dz[100038];
bool ove[100038];
void cle(void){
    for(int i=0;i<100017;i++){ove[i]=ncnt[i]=false;nc[i]=0;}
    car.clear();
    csy.clear();
    card.clear();
    seq.clear();
    ncn.clear();
    qj.clear();
    return;
}
void pri(yl xx){
    cout<<xx.fz<<"/"<<xx.fm;
    return;
}
ll mod=1000000;
void inp(void){
    ll LLL,V,dii,vi,ai,pii;
    scanf("%lld%lld%lld%lld",&n,&m,&LLL,&V);
    yl l=my(LLL,1);
    for(int i=1;i<=n;i++){
        scanf("%lld%lld%lld",&dii,&vi,&ai);
        //cout<<dii<<" "<<vi<<" "<<ai<<endl;
        yl di=my(dii,1);
        if(ai>=0&&vi>V){
            car.push_back(mp(di,l));
        }
        if(ai>0&&vi<=V){
            yl qd=(di+my(V*V-vi*vi,2*ai))+eps;
            if(qd<=l){car.push_back(mp(qd,l));}
        }
        if(ai<0&&vi>V){
            yl en=(di+my(vi*vi-V*V,2*(-ai)))-eps;
            if(en<l){car.push_back(mp(di,en));}
            else{car.push_back(mp(di,l));}
        }
    }
    for(ll i=1;i<=m;i++){
        scanf("%lld",&pii);
        csy.push_back(my(pii,1));
        seq.push_back(mp(my(pii,1),2ll*mod+i));
    }
    sort(car.begin(),car.end());
    for(ll i=0;i<car.size();i++){
        //if(i==2743){
        //    pri(car[i].fi);
        //    cout<<" ";
        //    pri(car[i].se);
        //    cout<<endl;
        //}
        seq.push_back(mp(car[i].fi,1ll*mod+i));
        seq.push_back(mp(car[i].se,3ll*mod+i));
    }
    sort(seq.begin(),seq.end());
    return;
}
void cld(void){
    ll ns=0;
    for(int kkk=0;kkk<seq.size();kkk++){
        ll pcur=seq[kkk].se;
        //cout<<pcur<<endl;
        if(pcur/mod==1){
            //if(pcur%mod==2743){cout<<"6666"<<endl;}
            ncn.push_back(pcur%mod);
            ncnt[pcur%mod]=true;
        }
        if(pcur/mod==3){
            if(nc[pcur%mod]!=0){
                card.push_back(mp(nc[pcur%mod],ns));
                //cout<<"P"<<endl;
                nc[pcur%mod]=0;
            }
            else{
                //cout<<"OK"<<endl;
                //cout<<pcur<<endl;
                ncnt[pcur%mod]=false;
                //ncn.erase(ncn.find(pcur%mod));
            }
        }
        if(pcur/mod==2){
            ns=pcur%mod;
            for(int i=0;i<ncn.size();i++){
                if(ncnt[ncn[i]]){
                    nc[ncn[i]]=ns;
                    ncnt[ncn[i]]=false;
                }
            }
            ncn.clear();
        }
    }
    cout<<card.size()<<" ";
    return;
}

void er(void){
    for(int i=0;i<card.size();i++){
        qj.push_back(mp(card[i].fi*3+1,i));
        qj.push_back(mp(card[i].se*3+2,i));
    }
    sort(qj.begin(),qj.end());
    ll ans=0;
    ll dzs=0;
    for(int kkk=0;kkk<qj.size();kkk++){
        pil pcur=qj[kkk];
        ll nf=pcur.se;
        //cout<<pcur.fi%3<<" "<<pcur.se<<endl;
        if(pcur.fi%3==1){
            dz[dzs++]=nf;
        }
        if(pcur.fi%3==2){
            if(!ove[nf]){
                //cout<<nf<<endl;
                ans++;
                for(int i=0;i<dzs;i++){ove[dz[i]]=true;}
                dzs=0;
            }
        }
    }
    cout<<m-ans<<endl;
    return;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ll t;
    scanf("%lld",&t);
    eps=my(1,2310);
    for(int kkkk=0;kkkk<t;kkkk++){
        cle();
        inp();
        cld();
        er();
    }
    return 0;
}
